﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using Maticsoft.Common;
using XinKuaiJi.Model;
namespace XinKuaiJi.BLL
{
    //t_user_info
    public partial class t_user_info
    {

        private readonly XinKuaiJi.DAL.t_user_info dal = new XinKuaiJi.DAL.t_user_info();
        public t_user_info()
        { }


        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long USER_ID)
        {
            return dal.Exists(USER_ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(XinKuaiJi.Model.t_user_info model)
        {
            return dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XinKuaiJi.Model.t_user_info model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long USER_ID)
        {

            return dal.Delete(USER_ID);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string USER_IDlist)
        {
            return dal.DeleteList(USER_IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XinKuaiJi.Model.t_user_info GetModel(long USER_ID)
        {

            return dal.GetModel(USER_ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public XinKuaiJi.Model.t_user_info GetModelByCache(long USER_ID)
        {

            string CacheKey = "t_user_infoModel-" + USER_ID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(USER_ID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (XinKuaiJi.Model.t_user_info)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XinKuaiJi.Model.t_user_info> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XinKuaiJi.Model.t_user_info> DataTableToList(DataTable dt)
        {
            List<XinKuaiJi.Model.t_user_info> modelList = new List<XinKuaiJi.Model.t_user_info>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XinKuaiJi.Model.t_user_info model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XinKuaiJi.Model.t_user_info();
                    if (dt.Rows[n]["USER_ID"].ToString() != "")
                    {
                        model.USER_ID = long.Parse(dt.Rows[n]["USER_ID"].ToString());
                    }
                    model.USER_NAME = dt.Rows[n]["USER_NAME"].ToString();
                    model.PASSWORD = dt.Rows[n]["PASSWORD"].ToString();
                    model.EMAIL = dt.Rows[n]["EMAIL"].ToString();
                    if (dt.Rows[n]["CREATE_TIME"].ToString() != "")
                    {
                        model.CREATE_TIME = DateTime.Parse(dt.Rows[n]["CREATE_TIME"].ToString());
                    }
                    model.STATUS = dt.Rows[n]["STATUS"].ToString();
                    if (dt.Rows[n]["ROLE_ID"].ToString() != "")
                    {
                        model.ROLE_ID = long.Parse(dt.Rows[n]["ROLE_ID"].ToString());
                    }
                    if (dt.Rows[n]["CHANNEL_ID"].ToString() != "")
                    {
                        model.CHANNEL_ID = long.Parse(dt.Rows[n]["CHANNEL_ID"].ToString());
                    }
                    if (dt.Rows[n]["UPDATE_TIME"].ToString() != "")
                    {
                        model.UPDATE_TIME = DateTime.Parse(dt.Rows[n]["UPDATE_TIME"].ToString());
                    }
                    model.DES1 = dt.Rows[n]["DES1"].ToString();
                    model.DES2 = dt.Rows[n]["DES2"].ToString();
                    model.DES3 = dt.Rows[n]["DES3"].ToString();


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion

    }
}